import http from "@/utils/http.js"

export const indexMixin = {
	data() {
		return {
			TabCur: 0,
			tabsList: [{
				id: 0,
				name: "全部"
			}],
			modalName: "",
			searchVal: "",
			PageCur: 1, //页码
			size: 10, //每页大小
			isShow: false
		}
	},
	onLoad() {
		this.initCategory()
	},
	methods: {
		//tab栏切换
		tabSelect(item) {
			if (this.TabCur === item.id) {
				return false
			}
			this.isShow = false
			this.TabCur = item.id
			this.PageCur = 1
			this.postsLast = []
			this.getFilmList()
		},
		//初始化分类
		initCategory() {
			var params = {
				url: '/film/filmCategory/list',
				method: 'GET',
				callBack: (res) => {
					this.tabsList = [{
						id: 0,
						name: "全部"
					}]
					this.tabsList.push(...res.data)
					//获取当前分类影视列表
					this.getFilmList()
				}
			};
			http.request(params);
		},
		//获取当前分类影视列表
		getFilmList() {
			this.loading = true
			let url = this.TabCur ?
				`/film/filmShort/filmPage/?filmCategoryId=${this.TabCur}&name=${this.searchVal}` :
				`/film/filmShort/filmPage/?name=${this.searchVal}`

			var params = {
				url: url,
				method: 'GET',
				data: {
					size: this.size,
					current: this.PageCur
				},
				callBack: (res) => {
					console.log(res);
					this.postsLast.push(...res.data.records)
					this.loading = false
					if (res.data.records < this.size) {
						this.isShow = true
					}
				}
			};
			http.request(params);
		},
		//搜索电影
		handerSearch() {
			var params = {
				url: `/film/filmShort/filmPage/?name=${this.searchVal}`,
				method: 'GET',
				callBack: (res) => {
					this.PageCur = 1;
					this.TabCur = 0
					this.postsLast = res.data.records
				}
			};
			http.request(params);
		}
	}
}